#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101

#include <Macros.h>
#include <CoVector.h>
#include <CoMatrix.h>
#include <CoCube.h>
#include <ValueHelpers.h>
#include <Settings.h>

#include <gen/QL/Termstructures/Volatility/Equityfx/LocalVolTermStructure.h>
#pragma unmanaged 
#include <ql\termstructures\volatility\equityfx\localvolcurve.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;

using namespace Cephei::QL::Times;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
namespace Cephei { namespace QL { namespace Termstructures { namespace Volatility { namespace Equityfx {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of ILocalVolCurve
	public ref class CLocalVolCurve : 
            public CLocalVolTermStructure,
            public Cephei::QL::Termstructures::Volatility::Equityfx::ILocalVolCurve
	{
	protected: 
		boost::shared_ptr<QuantLib::LocalVolCurve>* _ppLocalVolCurve;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::LocalVolCurve>* _phLocalVolCurve;
#endif
		Object^ _LocalVolCurveOwner;     // reference to object that manages the storage for this object
	internal:
		CLocalVolCurve (Cephei::QL::Termstructures::Volatility::Equityfx::IBlackVarianceCurve^ curve);
        CLocalVolCurve (boost::shared_ptr<QuantLib::LocalVolCurve>& childNative, Object^ owner);
        CLocalVolCurve (QuantLib::LocalVolCurve& childNative, Object^ owner);
        CLocalVolCurve (CLocalVolCurve^ copy);
        CLocalVolCurve (System::Type^ t);
#ifdef STRUCT
        CLocalVolCurve (QuantLib::LocalVolCurve childNative);
#endif       
#ifdef HANDLE
		CLocalVolCurve (QuantLib::Handle<QuantLib::LocalVolCurve>& childNative, Object^ owner);
		CLocalVolCurve (QuantLib::Handle<QuantLib::LocalVolCurve> childNative);
#endif
		virtual ~CLocalVolCurve ();
		!CLocalVolCurve ();

	internal:
		QuantLib::LocalVolCurve& GetReference ();
		boost::shared_ptr<QuantLib::LocalVolCurve>& GetShared ();
		QuantLib::LocalVolCurve* GetPointer ();
        void SetLocalVolCurve (boost::shared_ptr<QuantLib::LocalVolCurve> native)
        {
            if (_ppLocalVolCurve != NULL)
                delete _ppLocalVolCurve;
            _ppLocalVolCurve = new boost::shared_ptr<QuantLib::LocalVolCurve> (native);
            SetLocalVolTermStructure (boost::dynamic_pointer_cast<QuantLib::LocalVolTermStructure> (*_ppLocalVolCurve));
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::LocalVolCurve>& GetHandle ();
#endif
		virtual bool HasNative () override;
    public:
        property Cephei::QL::Times::IDayCounter^ DayCounter 
        {
		    virtual Cephei::QL::Times::IDayCounter^ get () ;
        }
        property DateTime MaxDate 
        {
		    virtual DateTime get () ;
        }
        property Double MaxStrike 
        {
		    virtual Double get () ;
        }
        property Double MinStrike 
        {
		    virtual Double get () ;
        }
        property DateTime ReferenceDate 
        {
		    virtual DateTime get () ;
        }
    };
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
	public ref class CLocalVolCurve_Factory : public System::MarshalByRefObject,  public ILocalVolCurve_Factory
	{
	public:
        virtual ILocalVolCurve^ Create (Cephei::QL::Termstructures::Volatility::Equityfx::IBlackVarianceCurve^ curve);
    };
   
/*Cephei*/ } /*QL*/ } /*Termstructures*/ } /*Volatility*/ } /*Equityfx */}
